package ru.agiledev.ws.client;

import ru.agiledev.akb.ws.AKBService;
import ru.agiledev.akb.ws.AkbObject;
import ru.agiledev.akb.ws.QType;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.URL;

/**
 * Created by a.kirillov
 * Date: 2/6/12 Time: 8:49 PM
 */
public class AKBServiceClient {
    private URL url = null;
    private AKBService akbService;

    public AKBServiceClient(URL url){
            this.url = url;

        //1st argument service URI, refer to wsdl document above
        //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://ws.akb.agiledev.ru/", "AKBServiceImplService");

        Service service = Service.create(url, qname);

        akbService = service.getPort(AKBService.class);
    }

    public AkbObject getObjectWithAspects(String objectName, QType type) throws Exception {
        AkbObject object = akbService.getObject(objectName, type);

        if(object == null) throw new Exception("Объект не был обнаружен в базе знаний");

        return object;
    }
}
